package com.yao.component.pictureselector;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by zwj on 2016/1/20.
 */
public class PictureDelete {
    private Context mContext;
    private ArrayList<String> pictureList;
    private onPictureDeleteListener mListener;
    private PictureDeleteReciver reciver;
    private int maxCount=-1;
    private int position;
    public PictureDelete(Context context,List<String> list,int position, onPictureDeleteListener listener){
        this.mContext=context;
        this.mListener=listener;
        this.pictureList=(ArrayList<String>) list;
        this.position=position;
        IntentFilter filter=new IntentFilter();
        filter.addAction("com.yao.component.pictureselector.deleteimage");
        reciver=new PictureDeleteReciver();
        mContext.registerReceiver(reciver,filter);

    }

    public void show(){
        Intent intent=new Intent(mContext,PreviewDeleteActivity.class);
        intent.putStringArrayListExtra("paths",pictureList);
        intent.putExtra("position",position);
        mContext.startActivity(intent);
    }
    class PictureDeleteReciver extends BroadcastReceiver{
        @Override
        public void onReceive(Context context, Intent intent) {
               if (mListener!=null){
                   mListener.onResult(intent.getStringArrayListExtra("result_image"));
               }

            mContext.unregisterReceiver(reciver);
        }
    }
    public interface onPictureDeleteListener{
        public void onResult(List<String> selectPath);

    }
}
